﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LiteStep.Conversions;
using LiteStep.Currencies;
using LiteStep.Exchanges;
using LiteStep.Exchanges.BtcE;
using LiteStep.Exchanges.MtGox;
namespace LiteStep.Test
{
	[TestClass]
	public class TestSimpleConversionManager
	{
		[TestMethod]
		public void TestSettingAndGetting()
		{
			var conversionManager = new SimpleConversionManager();
			Assert.AreEqual(null, conversionManager.Get<Btc, Usd, MtGox>());

			IConversion<Btc, Usd, MtGox> conversionFromBtcToUsdOnMtGox = new SimpleConversion<Btc, Usd, MtGox>(121.25M, DateTime.Now);
			conversionManager.Set(conversionFromBtcToUsdOnMtGox);

			conversionFromBtcToUsdOnMtGox = conversionManager.Get<Btc, Usd, MtGox>();
			Assert.AreSame(conversionFromBtcToUsdOnMtGox, conversionManager.Get<Btc, Usd, MtGox>());

			IConversion<Btc, Usd, BtcE> conversionFromBtcToUsdOnBtcE = new SimpleConversion<Btc, Usd, BtcE>(123.25M, DateTime.Now);
			conversionManager.Set(conversionFromBtcToUsdOnBtcE);

			Assert.AreSame(conversionFromBtcToUsdOnMtGox, conversionManager.Get<Btc, Usd, MtGox>());
			Assert.AreSame(conversionFromBtcToUsdOnBtcE, conversionManager.Get<Btc, Usd, BtcE>());

			var conversionsFromBtcToUsd = conversionManager.Get<Btc, Usd>().ToList();
			Assert.AreEqual(2, conversionsFromBtcToUsd.Count);
			
			Assert.IsTrue(conversionsFromBtcToUsd[0].Exchange.ExchangeType.Equals(new ExchangeType<MtGox>()));
			Assert.IsTrue(conversionsFromBtcToUsd[1].Exchange.ExchangeType.Equals(new ExchangeType<BtcE>()));

			var bestConversionFromBtcToUsd = conversionManager.GetBest<Btc, Usd>();
			Assert.AreSame(conversionFromBtcToUsdOnBtcE, bestConversionFromBtcToUsd);
		}
	}
}
